define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'sale/index',
                    add_url: 'sale/add',
                    edit_url: 'sale/edit',
                    del_url: 'sale/del',
                    multi_url: 'sale/multi',
                    config_url: 'sale/config',
                    table: 'sale',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('ID')},
                        {field: 'region_text', title: __('Region'),searchList: {"1":__('Region 1'),"2":__('Region 2'),"3":__('Region 3'),"4":__('Region 4')}, formatter: Table.api.formatter.normal},
                        {field: 'grade', title: __('Grade'), searchList: {"1":__('Grade 1'),"2":__('Grade 2'),"3":__('Grade 3'),"4":__('Grade 4'),"5":__('Grade 5')}, formatter: Table.api.formatter.normal},
                        {field: 'ronda', title: __('Ronda'), searchList: {"1":__('Ronda 1'),"2":__('Ronda 2'),"3":__('Ronda 3'),"4":__('Ronda 4'),"5":__('Ronda 5')}, formatter: Table.api.formatter.normal},
                        {field: 'lecturer', title: __('Lecturer')},
                        {field: 'host', title: __('Host')},
                        {field: 'finance', title: __('Finance')},
                        {field: 'book_total', title: __('Book_total')},
                        {field: 'office_total', title: __('Office_total')},
                        {field: 'metting_num', title: __('Metting_num')},
                        {field: 'hot_num', title: __('Hot_num')},
                        {field: 'uptime', title: __('Uptime'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        {field: 'endtime', title: __('Endtime'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        config: function () {
          Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            },
            formatter: {//渲染的方法
              province: function (value, row, index) {
                return '<a class="btn bg-success"> ' + value +','+row['city_text']+','+row['area_text']+'</a>';
              }
            },
        }
    };
    return Controller;
});